package pro.lingwu.station.service.impl;

import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import pro.lingwu.station.dao.StationMapper;
import pro.lingwu.station.dto.PagesResult;
import pro.lingwu.station.dto.db.Admin;
import pro.lingwu.station.dto.db.Station;
import pro.lingwu.station.service.StationService;

import java.util.List;

/**
 * @author @lingwu
 * @date created in 11/19/2021
 */
@Service
public class StationServiceImpl implements StationService {

    private final StationMapper mapper;

    public StationServiceImpl(StationMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public void addStation(Station station) {
        mapper.addStation(station);
    }

    @Override
    public void rmStation(Long id) {
        mapper.rmStation(id);
    }

    @Override
    public PagesResult<Station> getAllStations(int start, int size) {
        if (size>-1){
            PageHelper.startPage(start, size);
        }
        var res = new PagesResult<Station>();
        res.setTotal(mapper.getTotal());
        res.setResult(mapper.getAllStations());
        return res;
    }

    @Override
    public void updateStation(Station station) {
        mapper.updateStation(station);
    }

    @Override
    public Station findStationById(Long id) {
        return mapper.findStationBy(id);
    }
}
